package com.ba.base.view.dialog

import android.content.Context
import android.os.Handler
import android.util.DisplayMetrics
import android.view.Gravity
import androidx.core.content.ContextCompat
import com.ba.base.R

class ErrorDialog : BaseDialog {

    constructor(context: Context) : super(context)


    override fun getContentViewResId(): Int {
        return R.layout.base_dialog_error
    }

    override fun initView() {
    }

    override fun onSetContentViewAfter() {
        window?.run {
            setGravity(Gravity.CENTER)
            setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.shape_dialog_error))
            val windowManager = windowManager
            val display = windowManager.defaultDisplay
            val lp = attributes
            val displayMetrics = DisplayMetrics()
            display.getMetrics(displayMetrics)
            lp.width = (displayMetrics.widthPixels * 0.45).toInt()
            attributes = lp
        }
        setCancelable(false)
    }

    override fun show() {
        super.show()
        Handler {
            dismiss()
            false
        }.sendEmptyMessageDelayed(100, 2000)
    }
}